﻿using Futaba.SBus.Telemetry;
using Futaba.SBus.Telemetry.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Futaba.SBus.Tests.Telemetry
{
	partial class SlotValueParserTests
	{

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Current")]
		public void ParseCurrent_Current()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 80.2;
			var parameter = GetParameter(_sensors, SensorType.CurrentSensor, SensorValueType.Raw);
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x1F, 0x54 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Current")]
		public void ParseCurrent_Voltage()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 80.2;
			var parameter = GetParameter(_sensors, SensorType.CurrentSensor, SensorValueType.Volt, "VOLTAGE");
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x1F, 0x54 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Current")]
		public void ParseCurrent_Capacity()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 4200;
			var parameter = GetParameter(_sensors, SensorType.CurrentSensor, SensorValueType.Volt, "CAPACITY");
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x10, 0x68 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

	}
}
